"""
Author: HuWen
@file: page_ProductManagement.py
@dateTime: 2025/8/13 16:24
加油加油！！！
"""

from playwright.sync_api import Page
from common.base_page import BasePage
from locators.basicSecurityInformation.basicProcessInfo.loc__product_management import LocatorProductManagement


class ProductManagementPage(BasePage):
    def __init__(self, page: Page):
        super().__init__(page)
        self.switch_menu("安全基础管理")
        self.switch_menu("生产档案(企业)")


    def navigate_to_product_management(self):
        """导航到产品管理页面"""

        self.check(LocatorProductManagement.loc_product_management_radio)

    def create_product(self):
        """创建产品流程"""
        self.click(LocatorProductManagement.loc_create_product_button)
        # 选择项目名称
        self.select(LocatorProductManagement.loc_project_name_select,text='20250321')

        # 输入产品名称
        self.click(LocatorProductManagement.loc_product_name_input)

        self.fill(LocatorProductManagement.loc_product_name_input, "Ui产品")
        # 选择危险化学品
        self.select(LocatorProductManagement.loc_chemical_select,text='氨')
        # 填写产品描述
        self.click(LocatorProductManagement.loc_product_desc_input)
        self.fill(LocatorProductManagement.loc_product_desc_input, "ui产品描述")
        # 填写产品产量及单位
        self.click(LocatorProductManagement.loc_product_output_input)
        self.fill(LocatorProductManagement.loc_product_output_input, "111")

        # click_with_parent  相同类型的下拉元素出现在页面上，对弹窗元素与主界面元素进行了区分
        # self.click_with_parent(LocatorProductManagement.loc_unit_combobox)

        # 填写其他信息
        self.click(LocatorProductManagement.loc_cas_input)  # 空输入
        self.click(LocatorProductManagement.loc_physical_state_input)
        self.fill(LocatorProductManagement.loc_physical_state_input, "ui物理状态")
        self.click(LocatorProductManagement.loc_packaging_input)
        self.fill(LocatorProductManagement.loc_packaging_input, "ui包装")
        self.click(LocatorProductManagement.loc_max_storage_input)
        self.fill(LocatorProductManagement.loc_max_storage_input, "12233")
        # 提交创建
        self.click(LocatorProductManagement.loc_confirm_button)

    def query_product(self):
        """查询产品"""
        self.click(LocatorProductManagement.loc_project_query_input)
        self.fill(LocatorProductManagement.loc_project_query_input, "20250321")
        self.click(LocatorProductManagement.loc_query_button)
        self.click(LocatorProductManagement.loc_close_view)

    def view_and_edit_product(self):
        """查看并编辑产品"""
        self.click(LocatorProductManagement.loc_view_button)
        self.click(LocatorProductManagement.loc_edit_button)
        # 编辑产品描述
        self.click(LocatorProductManagement.loc_product_desc_input)
        self.fill(LocatorProductManagement.loc_product_desc_input, "ui产品描述\n编辑")
        self.page.get_by_role(
            LocatorProductManagement.loc_product_desc_input['loc_role'],
            name=LocatorProductManagement.loc_product_desc_input['loc_name']
        ).press("CapsLock")
        self.fill(LocatorProductManagement.loc_product_desc_input, "ui产品描述\n编辑UI")
        self.page.get_by_role(
            LocatorProductManagement.loc_product_desc_input['loc_role'],
            name=LocatorProductManagement.loc_product_desc_input['loc_name']
        ).press("CapsLock")
        self.click(LocatorProductManagement.loc_confirm_button)

    def delete_product(self):
        """删除产品"""
        self.click(LocatorProductManagement.loc_delete_button)
        self.click(LocatorProductManagement.loc_delete_confirm_button)